using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Modeling;

namespace Microsoft.Modeling.StoryboardDesigner
{
    public partial class StoryboardDesignerDomainModel
    {
        /// <summary>
        /// Register the custom-coded "MultiLineCompartment" shape
        /// </summary>
        /// <returns></returns>
        private void AddMultiLineCompartmentTypes(List<System.Type> types)
        {
            // Add the new MultiLineCompartment domain class
            types.Add(typeof(MultiLineCompartment));

            // Add the rules for updating ScenarioShape compartments
            types.Add(typeof(ScenarioShapeCompartmentItemAddRule));
            types.Add(typeof(ScenarioShapeCompartmentItemChangeRule));
        }

        /// <summary>
        /// Register the properties of the custom-coded MultiLineCompartment shape
        /// </summary>
        /// <returns></returns>
        protected override DomainMemberInfo[] GetCustomDomainProperties()
        {
            List<DomainMemberInfo> properties = new List<DomainMemberInfo>();

            properties.AddRange(base.GetCustomDomainProperties());

            properties.Add(
                new DomainMemberInfo(typeof(MultiLineCompartment),
                "CustomDisplayProperty",
                MultiLineCompartment.CustomDisplayPropertyDomainPropertyId,
                typeof(MultiLineCompartment.CustomDisplayPropertyPropertyHandler)));

            return properties.ToArray();
        }

        /// <summary>
        /// Override: CreateElement needs to be able to generate instances
        /// of the custom-coded "MultiLineCompartment".
        /// </summary>
        /// <remarks>NB the base text template has been altered so that the 
        /// generated class contains a method called "GeneratedCreateElement"
        /// rather than the usual "CreateElement".</remarks>
        public override ModelElement CreateElement(
            Partition partition,
            Type elementType,
            PropertyAssignment[] propertyAssignments)
        {

            if(elementType == null)
            {
                throw new global::System.ArgumentNullException("elementType");
            }

            if(elementType == typeof(MultiLineCompartment))
            {
                return new MultiLineCompartment(partition, propertyAssignments);
            }

            return GeneratedCreateElement(partition, elementType, propertyAssignments);
        }
    }
}